//home模块的小仓库

import {reqCategoryList,reqGetBannerList,reqGetFloorList} from '@/api'

const state = {
    categoryList:[],
    bannerList:[],
    floorList:[],
};
const actions = {
    // 需要异步等待信息
    async getcategoryList({commit}){
        let result = await reqCategoryList();
        if(result.code == 200){
            commit("GETCATEGORYLIST",result.data)
        }
        // console.log(result)
    },
    // 获取首页的轮播图数据
    async getBannerList({commit}){
        let result = await reqGetBannerList();
        if(result.code == 200){
            commit("GETBANNERLIST",result.data)
        }
        // console.log(result)
    },
    async getFloorList({commit}){
        let result = await reqGetFloorList();
        if(result.code == 200){
            commit("GETFLOORLIST",result.data)
        }
        // console.log(result)
    }
};
const mutations = {
    GETCATEGORYLIST(state,categoryList){
        // 由于接口多了一个,所以截去
        state.categoryList = categoryList.slice(0,15)
    },
    // 轮播图
    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
        // console.log(state.floorList)
    }
};
const getters = {};

export default {
    state,
    mutations,
    actions,
    getters,
}